home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_07
/
1107125a
< prev
next >
Wrap
Text File
|
1993-05-05
|
601b
|
41 lines
//
// list.cpp - list implementation using a nested class
// with a static data member for counting the objects
//
#include <stdio.h>
#include "list.h"
unsigned list::count = 0;
list::list(unsigned n)
{
first = last = new node (n, 0);
++count;
}
list::~list()
{
node *p;
while ((p = first) != 0)
{
first = first->next;
delete p;
}
--count;
}
void list::add(unsigned n)
{
if (last->number != n)
last = last->next = new node (n, 0);
}
void list::print()
{
for (node *p = first; p != 0; p = p->next)
printf("%4u ", p->number);
}